var that
var app = getApp();
Page({
  data: {
    inputValue:"",
    f: '',//从哪里跳到此界面，支付成功是否刷新上一界面，b代表要刷新暂时未用
  },
  onLoad: function (options) {
    that=this;
    console.log(options);
    if (options.f) { that.setData({ f: options.f }) }
  },
  onReady: function () {
  
  },

  onShow: function () {
    app.ispoint = 0;
  },
  bindKeyInput:function(e){
    this.setData({
      inputValue: e.detail.value.trim()
    })
  },
  addm:function(){
    if (that.data.inputValue == '') { app.toast_up("请输入金额");return}
    console.log(app.data.openid)
    if (app.ispoint == 1) { return; } else { app.ispoint = 1; }//弹出支付框后就不允许执行了
    app.req("add_money", { "openid": app.data.openid, "money": that.data.inputValue,"shop_id":wx.getStorageSync('shop_id') }, function (res) {
     
      if (res.status == "success") {
        that.wx_pay(res.mess)
      } else if (res.status == "error") {
        app.ispoint = 0;
        app.toast_up(res.mess)
      } else {
        app.ispoint = 0;
        app.modal("错误提示", "网络错误，是否重试？", function (re) {
          if (re) {
            that.addm()
          }
        })
      }
    })
  },
  wx_pay: function (pay_msg) {
    wx.requestPayment(
      {
        'timeStamp': pay_msg.timeStamp,
        'nonceStr': pay_msg.nonceStr,
        'package': pay_msg.package,
        'signType': pay_msg.signType,
        'paySign': pay_msg.paySign,
        'success': function (re) {
          that.success();
        },
        'fail': function (re) {
          app.ispoint = 0;
          app.toast_up("支付失败！")
        },
        'complete': function (res) { }
      })
  },
  success:function(){
   
    app.toast("支付成功！")
    app.get_msg_rr();  //充值成功后刷新人人商城的信息
    setTimeout(function () { wx.navigateBack({ delta: 1 }) }, 2000)
  }
})